package cn.abellflower.flowerhomehandler.home.vo;

import lombok.Data;
import org.hibernate.validator.constraints.Length;

import javax.validation.Valid;
import javax.validation.constraints.Min;
import javax.validation.constraints.NotNull;

/**
 * @Description
 * @Author gbzdyf@126.com
 * @Date 2020/12/27 上午10:15
 */
@Data
public class ValidVo {

    private Long userId;

    @NotNull(groups = Save.class)
    @Length(min = 2, max = 100, message = "用户名不得小于", groups = Save.class)
    private String userName;

    @NotNull
    @Length(min = 2, max = 32, message = "用户名不得小于")
    private String account;

    @NotNull
    @Length(min = 6, max = 15, message = "密码不得小于")
    private String password;

    /**
     * 嵌套校验
     */
    @NotNull(groups = {Save.class, Update.class})
    @Valid
    private Job job;

    @Data
    public static class Job {

        @Min(value = 1, groups = Update.class)
        private Long jobId;

        @NotNull(groups = {Save.class, Update.class})
        @Length(min = 2, max = 10, groups = {Save.class, Update.class})
        private String jobName;

        @NotNull(groups = {Save.class, Update.class})
        @Length(min = 2, max = 10, groups = {Save.class, Update.class})
        private String position;
    }


    /**
     * 保存时候分组校验
     */
    public interface Save {

    }

    /**
     * 更新时候分组校验
     */
    public interface Update {

    }
}
